package com.example.controller;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

// 通过实现Controller接口实现的控制器
public class FirstController implements Controller {
    @Override
    public ModelAndView handleRequest(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws Exception {
        // 创建ModelAndView对象
        ModelAndView modelAndView = new ModelAndView();

        // 往模型对象中添加数据
        modelAndView.addObject("message", "Hello World");

        // 设置逻辑视图名
        modelAndView.setViewName("/WEB-INF/jsp/index.jsp");

        // 返回ModelAndView对象
        return modelAndView;
    }
}
